import network as nt
import ntptime

wlan = nt.WLAN(nt.STA_IF)
wlan.active(True) 

try:
    with open('/sd/data/conf.cot') as f:exec(f.read())
except:
    pass

computer = [2,2,3,2,4,2,5,2,6,2,7,2,2,3,2,4,2,5,7,3,7,4,7,5,3,5,4,5,5,5,6,5,1,7,2,7,3,7,4,7,5,7,6,7,7,7,8,7]
wifi_off = [4,2,5,2,4,7,5,7,2,4,2,5,7,4,7,5]
wifi_on  = [4,2,5,2,4,7,5,7,2,4,2,5,7,4,7,5,4,4,5,4,4,5,5,5]
f0       = [1,2,2,2,3,2,1,4,3,4,1,6,2,6,3,6,1,3,3,3,1,5,3,5]
f1       = [2,2,2,3,2,4,2,5,2,6]
f2       = [1,2,2,2,3,2,1,4,2,4,3,4,1,6,2,6,3,6,3,3,1,5]
f3       = [1,2,2,2,3,2,1,4,2,4,3,4,1,6,2,6,3,6,3,3,3,5]
f4       = [1,2,1,4,2,4,3,4,3,6,1,3,3,5,3,2,3,3]
f5       = [1,2,2,2,3,2,1,4,2,4,3,4,1,6,2,6,3,6,1,3,3,5]
f6       = [1,2,2,2,3,2,1,4,2,4,3,4,1,6,2,6,3,6,1,3,1,5,3,5]
f7       = [1,2,2,2,3,2,3,3,3,4,3,5,3,6]
f8       = [1,2,2,2,3,2,1,4,2,4,3,4,1,6,2,6,3,6,1,3,3,3,1,5,3,5]
f9       = [1,2,2,2,3,2,1,4,2,4,3,4,1,6,2,6,3,6,1,3,3,3,3,5]
fcen     = [1,4,2,4,3,4]
fspa     = []
fpo      = [2,6]

def PixelOn(display, data, fill=1):
    c = 0
    x = 0
    y = 0
    for t in data:
        if c == 0 or c == 1:
            x = t
            c = c + 1
        elif c == 2:
            y = t
            c = c + 1
            display.pixel(x, y, fill)
        elif c == 3:c = 0

def ico(display, data, x, y, fill=1):
    ico = []
    c = 0
    for i in data:
        if c == 0:
            ico.append(i+x)
            c = 1
        if c == 1:
            ico.append(i+y)
            c = 0
    PixelOn(display, ico, fill)

def fill(display, x, y, length, width, fill=0):
    for l in range(0, length):
        for w in range(0, width):display.pixel(x+l, y+w, fill)

def fontnumber(display, number, x, y, fill=1):
    if number == 0:
        for l in [8,9,10,39,40,41]:
            for i in range(0, 17):
                display.pixel(i+4+x, l+y, fill)
        for l in [4,5,6,18,19,20]:
            for i in range(0, 18):
                display.pixel(l+x, i+8+y, fill)
        for l in [4,5,6,18,19,20]:
            for i in range(0, 18):
                display.pixel(l+x, i+23+y, fill)
    if number == 1:
        for l in [11,12,13]:
            for i in range(0, 34):
                display.pixel(l+x, i+8+y, fill)
    if number == 2:
        for l in [8,9,10,23,24,25,39,40,41]:
            for i in range(0, 17):
                display.pixel(i+4+x, l+y, fill)
        for l in [18,19,20]:
            for i in range(0, 18):
                display.pixel(l+x, i+8+y, fill)
        for l in [4,5,6]:
            for i in range(0, 18):
                display.pixel(l+x, i+23+y, fill)
    if number == 3:
        for l in [8,9,10,23,24,25,39,40,41]:
            for i in range(0, 17):
                display.pixel(i+4+x, l+y, fill)
        for l in [18,19,20]:
            for i in range(0, 18):
                display.pixel(l+x, i+8+y, fill)
        for l in [18,19,20]:
            for i in range(0, 18):
                display.pixel(l+x, i+23+y, fill)
    if number == 4:
        for l in [23,24,25]:
            for i in range(0, 17):
                display.pixel(i+4+x, l+y, fill)
        for l in [4,5,6,18,19,20]:
            for i in range(0, 18):
                display.pixel(l+x, i+8+y, fill)
        for l in [18,19,20]:
            for i in range(0, 18):
                display.pixel(l+x, i+23+y, fill)
    if number == 5:
        for l in [8,9,10,23,24,25,39,40,41]:
            for i in range(0, 17):
                display.pixel(i+4+x, l+y, fill)
        for l in [4,5,6]:
            for i in range(0, 18):
                display.pixel(l+x, i+8+y, fill)
        for l in [18,19,20]:
            for i in range(0, 18):
                display.pixel(l+x, i+23+y, fill)
    if number == 6:
        for l in [8,9,10,23,24,25,39,40,41]:
            for i in range(0, 17):
                display.pixel(i+4+x, l+y, fill)
        for l in [4,5,6]:
            for i in range(0, 18):
                display.pixel(l+x, i+8+y, fill)
        for l in [4,5,6,18,19,20]:
            for i in range(0, 18):
                display.pixel(l+x, i+23+y, fill)
    if number == 7:
        for l in [8,9,10]:
            for i in range(0, 17):
                display.pixel(i+4+x, l+y, fill)
        for l in [18,19,20]:
            for i in range(0, 18):
                display.pixel(l+x, i+8+y, fill)
        for l in [18,19,20]:
            for i in range(0, 18):
                display.pixel(l+x, i+23+y, fill)
    if number == 8:
        for l in [8,9,10,23,24,25,39,40,41]:
            for i in range(0, 17):
                display.pixel(i+4+x, l+y, fill)
        for l in [4,5,6,18,19,20]:
            for i in range(0, 18):
                display.pixel(l+x, i+8+y, fill)
        for l in [4,5,6,18,19,20]:
            for i in range(0, 18):
                display.pixel(l+x, i+23+y, fill)
    if number == 9:
        for l in [8,9,10,23,24,25,39,40,41]:
            for i in range(0, 17):
                display.pixel(i+4+x, l+y, fill)
        for l in [4,5,6,18,19,20]:
            for i in range(0, 18):
                display.pixel(l+x, i+8+y, fill)
        for l in [18,19,20]:
            for i in range(0, 18):
                display.pixel(l+x, i+23+y, fill)

def icodate(display, data, x=0, y=0, fill=1):
    add = 0
    for f in data:
        if f == '0':ico(display, f0, x, y+add, fill)
        if f == '1':ico(display, f1, x, y+add, fill)
        if f == '2':ico(display, f2, x, y+add, fill)
        if f == '3':ico(display, f3, x, y+add, fill)
        if f == '4':ico(display, f4, x, y+add, fill)
        if f == '5':ico(display, f5, x, y+add, fill)
        if f == '6':ico(display, f6, x, y+add, fill)
        if f == '7':ico(display, f7, x, y+add, fill)
        if f == '8':ico(display, f8, x, y+add, fill)
        if f == '9':ico(display, f9, x, y+add, fill)
        if f == '-':ico(display, fcen, x, y+add, fill)
        if f == ' ':ico(display, fspa, x, y+add, fill)
        if f == '.':ico(display, fpo, x, y+add, fill)
        add = add + 5

def feng(display, x, y, fill=1):
    for l in [11,12,13]:
        for i in range(13, 16):
            display.pixel(l+x, i+y, fill)
        for i in range(34, 37):
            display.pixel(l+x, i+y, fill)

def ftpp(dis):
    
    dis.line(36,23,46,23,1)
    dis.line(36,23,36,37,1)
    dis.pixel(46, 24, 1)
    dis.pixel(37, 37, 1)
    dis.rect(38,25,10,14,1)

    dis.rect(40,27,6,1,1)
    dis.rect(40,29,6,1,1)
    dis.rect(40,31,6,1,1)
    dis.pixel(41, 27, 0)
    dis.pixel(41, 29, 0)
    
    dis.rect(80,27,10,1,1)
    dis.rect(80,29,10,1,1)
    dis.pixel(81, 27, 0)
    dis.pixel(81, 29, 0)

    dis.rect(78,25,14,9,1)
    dis.rect(55,30,17,1,1)
    dis.rect(55,32,17,1,1)
    dis.rect(62,29,1,5,1)
    dis.rect(64,29,1,5,1)
    dis.rect(75,36,20,1,1)
    dis.rect(68,45,4,4,1)
    dis.rect(68,49,1,3,1)
    dis.rect(55,45,4,1,1)
    dis.rect(55,48,4,1,1)
    dis.rect(55,45,1,7,1)
    dis.rect(61,45,5,1,1)
    dis.rect(63,45,1,7,1)

    dis.show()